package com.xie.web;

import com.xie.mapper.UserMapper;
import com.xie.pojo.BaiduWapTj;
import com.xie.service.BaiduWapService;
import com.xie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@PreAuthorize("hasRole('ADMIN')")
public class BaiduWap {

    @Autowired
    BaiduWapService baiduWapService;

    @Autowired
    UserService userService;
    @PostMapping("/addzy")
    public void submitZy(BaiduWapTj baiduWapTj){
        //System.out.println("baiduWapTj = " + baiduWapTj);
        baiduWapService.insert(baiduWapTj);
    }



    @RequestMapping("/pass")
    @Transactional
    public void passZy(Integer id,Integer uid){
        new Thread(()->userService.addMoney(uid)).start();
        baiduWapService.sumbitZy(id);
    }

    @RequestMapping("/nopass")
    @Transactional
    public void nopassZy(Integer id, Integer uid){
        new Thread(()->userService.nopass(uid)).start();
        baiduWapService.deleteZy(id);
    }
}
